package top.superflow.db.api

import scala.reflect.runtime.{ universe => ru }
import ru._

class DBField {
  
  private var _name : String = _
  
  private var _fieldType : String = _
  
  private var _indexes : List[DBIndex] = _
  
  private var _length : Int = _
  
  private var _defaultValue : String = _
  
  private var _nullable : Boolean = _
  
  private var _precision : Int = _
  
  private var _scale : Int = _
  
  def name = _name
  def name_=(name : String){
    this._name=name
  }
  def fieldType = _fieldType
  def fieldType_=(fieldType : String){
    this._fieldType=fieldType
  }
  
  def indexes = _indexes
  def indexes_= (indexes : List[DBIndex]){
    this._indexes = indexes
  }
  
  def length = _length
  def length_= (length : Int){
    this._length = length
  }

  def defaultValue = _defaultValue
  def defaultValue_=(defaultValue: String) {
    this._defaultValue = defaultValue
  }
  
  def nullable=_nullable
  def nullable_= (nullable : Boolean){
    this._nullable = nullable
  }
  
  def precision=_precision
  def precision_= (precision : Int) {
    this._precision = precision
  }
  
  def scale=_scale
  def scale_=(scale : Int){
    this._scale = scale
  }
}

object DBField {
  
  def getAllGetterForCriticalProperty = {
    val getters = List()
    typeOf[DBField].members.filter(s => 
      
        s.isMethod 
        && s.asMethod.isGetter 
        && !(s.asMethod.name.toString contains "indexes")
        && !(s.asMethod.name.toString contains "defaultValue")
        ).map { x => x.asMethod}
  }
  
  def main(args: Array[String]): Unit = {
    for(getter <- getAllGetterForCriticalProperty){
      println(getter.name)
    }
  }
}